package com.shujia.day17.lambda1;

import java.util.ArrayList;

public class Operator5 {
    public static void main(String[] args) {
        ArrayList<Staff> staffs = new ArrayList<>();
        staffs.add(new Staff("易政", 18, 12000));
        staffs.add(new Staff("李国涛", 19, 20000));
        staffs.add(new Staff("刘俊杰", 13, 8000));
        staffs.add(new Staff("陆玉龙", 12, 6000));


        /*
                Lambda表达式的基本语法：
                    () -> {} 表示定义的为一个函数 ,其中 () 表示函数的参数列表，{}表示的是函数的方法体
                将函数赋值给一个接口的变量，让接口中定义的抽象方法能够实现
         */

        Filter filter = (ArrayList<Staff> list, int salary) -> {
            ArrayList<Staff> arrayList = new ArrayList<>();
            for (Staff staff : list) {
               if(staff.salary <= salary){
                   arrayList.add(staff);
               }
            }
            return arrayList;
        };

        System.out.println(filter.filter(staffs, 8000));
        System.out.println(staffs);

    }

    static interface Filter {
        public ArrayList<Staff> filter(ArrayList<Staff> staffs, int salary);
    }

}
